package com.major.dawn.leetCode.array;

public class MissingNumber {

    public int missingNumber(int[] nums) {
        int length = nums.length;
        int sum = (1 + length) * length / 2;
        int cul = 0;
        for (int i = 0; i < length; i++) {
            cul = cul + nums[i];
        }
        return sum - cul;
    }


//    对一个数值异或两次等于其自身
//    数学的思想真的太巧秒了 ，我真的太垃圾了
    public int missingNumber2(int[] nums) {
        int res = 0;
        for (int i = 0; i < nums.length; ++i) {
            res ^= i;
            res ^= nums[i];
        }
        res ^= nums.length;

        return res;
    }

    public static void main(String[] args) {
        int n = 67;
        System.out.println(Integer.toBinaryString(n));
         n = n ^ 3;
        System.out.println(Integer.toBinaryString(3));
        System.out.println(Integer.toBinaryString(n));
        n = n ^ 3;
        System.out.println(Integer.toBinaryString(n));

    }




}
